package com.example.springboot.controller;

import com.example.springboot.bean.Department;
import com.example.springboot.bean.Employee;
import com.example.springboot.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by tang on 2017/12/8.
 */
@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;


    @RequestMapping("/list")
    public String departmentList(Map<String, Object> maps,
                                 @RequestParam(defaultValue = "10") int pageSize,
                                 @RequestParam(defaultValue = "1") int pageNo) {

        PageRequest pageRequest = new PageRequest(pageNo - 1, pageSize);
        Iterable<Department> departments = departmentService.findAll(pageRequest);
        long count = departmentService.count();
        maps.put("pageNo", pageNo);
        maps.put("pageSize", pageSize);
        maps.put("count", count);
        maps.put("departments", departments);
        return "department/department-list";

    }


    @ResponseBody
    @RequestMapping("/findAll")
    public Iterable<Department> departmentList() {
        Iterable<Department> departments = departmentService.findAll(null);
        return departments;

    }


}
